package nio.server;


import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class NioClient {
    public static void main(String[] args) throws IOException {
        //通道
        SocketChannel socketChannel = SocketChannel.open();
        //设置非阻塞
        socketChannel.configureBlocking(false);
        //提供服务器端的端口
        InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.1", 6666);
        //连接服务器
        if (!socketChannel.connect(inetSocketAddress)){
            while (!socketChannel.finishConnect()){
                System.out.println("未连接上，客户端不阻塞，做其他事情");
            }
        }
        String str = "hello,嘟嘟嘟";
        ByteBuffer byteBuffer = ByteBuffer.wrap(str.getBytes());
        //发送数据
        socketChannel.write(byteBuffer);
        System.in.read();
    }
}
